
//引入url模块
const url = require("url");

const path = "http://nodejs.cn/node/api_count?v=fs.html%23fs_fs_stat_path_options_callback";

//对url地址解析
//加true使query变成一个对象
const result = url.parse(path,true);

console.log(result)

//在cmd中复制，右键-标记-回车

/*

Url {
  protocol: 'http:',协议
  slashes: true,
  auth: null,证书认证
  host: 'nodejs.cn',域名
  port: null,端口号
  hostname: 'nodejs.cn',独立域名
  hash: null,哈希值
  search: '?v=fs.html%23fs_fs_stat_path_options_callback',
  query: { v: 'fs.html#fs_fs_stat_path_options_callback' },
  pathname: '/node/api_count',
  path: '/node/api_count?v=fs.html%23fs_fs_stat_path_options_callback',
  href: 'http://nodejs.cn/node/api_count?v=fs.html%23fs_fs_stat_path_options_cal
lback' }

*/


//组装url
let urlobj = {
  protocol:"http",
  hostname:"www.kt.com",
  pathname:"/html/kt",
  port:8080,
  query:{
    leave:3
  },
  hash:"#test"
}
const result1 = url.format(urlobj)
console.log(result1)
//http://www.kt.com:8080/html/kt?leave=3#test